/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.gov.cemaden.library.model.smp;

import br.gov.cemaden.library.model.BaseEntity;
import java.io.Serializable;
import java.util.Set;
import java.util.TreeSet;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.codehaus.jackson.annotate.JsonManagedReference;

/**
 *
 * @author paulo.dias
 */
@Entity
@Table(name = "smp_whosys", schema = "smp")
@SequenceGenerator(name = "sequence", sequenceName = "smp.smp_whosys_sequence", schema = "smp")
@NamedQueries({
    @NamedQuery(name = "WhoSys.findAll", query = "SELECT a FROM WhoSys a ORDER BY a.id ASC"),
    @NamedQuery(name = "WhoSys.findById", query = "SELECT a FROM WhoSys a WHERE a.id = :id"),
    @NamedQuery(name = "WhoSys.findByHostName", query = "SELECT a FROM WhoSys a WHERE a.hostName = :hostName"),
    @NamedQuery(name = "WhoSys.findByHostAddressAndHostName", query = "SELECT a FROM WhoSys a WHERE a.hostAddress = :hostAddress AND a.hostName = :hostName"),
    @NamedQuery(name = "WhoSys.findByHostAddress", query = "SELECT a FROM WhoSys a WHERE a.hostAddress = :hostAddress"),})
public class WhoSys implements Serializable, BaseEntity {
           
    @Id
    @GeneratedValue(generator = "sequence", strategy = GenerationType.AUTO)
    @Column(name = "id_whosys", nullable = false, unique = true)
    private Long id;
    
    @Column(name = "host_name", length = 100, nullable = true)
    private String hostName;
    
    @Column(name = "host_address", length = 100, nullable = true)
    private String hostAddress;
    
    @OneToMany(mappedBy = "whoSys", cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
    @OrderBy("data DESC")
    @JsonManagedReference
    private Set<ExecHardware> execucoes;
    
    public WhoSys() {
        execucoes = new TreeSet<ExecHardware>();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Set<ExecHardware> getExecucoes() {
        return execucoes;
    }

    public void setExecucoes(Set<ExecHardware> execucoes) {
        this.execucoes = execucoes;
    }
     
    public String getHostName() {
        return hostName;
    }

    public void setHostName(String hostName) {
        this.hostName = hostName;
    }

    public String getHostAddress() {
        return hostAddress;
    }

    public void setHostAddress(String hostAddress) {
        this.hostAddress = hostAddress;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 13 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final WhoSys other = (WhoSys) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "WhoSys{ id=" + id + ", hostName=" + hostName + ", hostAddress=" + hostAddress + '}';
    }
}
